﻿using Abp.Authorization;
using Abp.Authorization.Roles;
using Abp.MultiTenancy;
using Abp.Zero.Configuration;

namespace AbpProjectTemplate.Domain.Roles
{
    public static class AppRoleConfig
    {
        public const string AdminRoleName = "Admin";
        public const string HostAdminRoleDisplayName = "系统管理员";
        public const string TenantAdminRoleDisplayName = "系统管理员";

        public static void Init(this IRoleManagementConfig roleManagementConfig)
        {
            //静态超级管理员角色，只要角色名和此相等，默认授予所有权限
            roleManagementConfig.StaticRoles.Add(
                new StaticRoleDefinition(
                    roleName: AdminRoleName,
                    side: MultiTenancySides.Host,
                    grantAllPermissionsByDefault: true
                )
            );

            //租户静态超级管理员角色，默认授予所有权限
            roleManagementConfig.StaticRoles.Add(
                new StaticRoleDefinition(
                    roleName: AdminRoleName,
                    side: MultiTenancySides.Tenant,
                    grantAllPermissionsByDefault: true
                )
            );
        }

        /// <summary>
        /// 创建默认管理员角色 
        /// </summary>
        public static Role CreateAdminRole(int? tenantId = null)
        {
            var role = new Role(tenantId, AdminRoleName, HostAdminRoleDisplayName)
            {
                IsStatic = true
            };

            return role;
        }
    }
}

